<template>
	<view class="base-page yangsf-flex-row-center">
		<view class="yangsf-ratio-w-50">
			<u-button type="primary" loading shape="circle" text="微信登录中"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		domain
	} from '@/config/config'
	import {
		wxMpLogin
	} from '@/config/api.js'
	export default {
		data() {
			return {

			}
		},
		created() {
			this.getCode()
		},
		methods: {
			getCode() {
				let code = "";
				let userId = "";
				let url = window.location.href;
				console.log("获取网页地址 ==> {}", url);
				if (url) {
					let temp = url.split("?")[1];
					console.log("获取参数 ==> {}", temp);
					if (temp) {
						let parts = temp.split("&");
						console.log("获取参数 parts ==> {}", parts);
						if (parts) {
							for (let i = 0; i < parts.length; i++) {
								const pp = parts[i].split("=");
								if (pp && pp[0] == "code") {
									code = pp[1];
									console.log("code ==> {}", code);
								} else if (pp && pp[0] == "state") {
									userId = pp[1];
								}
							}

							let data = {
								code: code,
								userId: userId
							}
							wxMpLogin(data).then(res => {
								console.log("微信登录成功 ==> {}", res);
								this.$store.commit('setUserInfo', res.data);
								window.location.href = domain
								// uni.switchTab({
								// 	url: '/pages/index/index'
								// })
							})
						}
					}
				}
			},
		}
	}
</script>

<style>

</style>